package com.xique.door.device.freeview.controller;

import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.device.freeview.bean.domain.FreeviewEventRecord;
import com.xique.door.device.freeview.service.IFreeviewEventRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 全视通事件结果记录Controller
 * 
 * @author caogq
 * @date 2021-10-21
 */
@Controller
@RequestMapping("/oms/record")
public class FreeviewEventRecordController extends BaseController
{
    private String prefix = "oms/record";

    @Autowired
    private IFreeviewEventRecordService freeviewEventRecordService;

    @PreAuthorize(hasPermi ="oms:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询全视通事件结果记录列表
     */
    @PreAuthorize(hasPermi ="oms:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FreeviewEventRecord freeviewEventRecord)
    {
        startPage();
        List<FreeviewEventRecord> list = freeviewEventRecordService.selectFreeviewEventRecordList(freeviewEventRecord);
        return getDataTable(list);
    }

    /**
     * 导出全视通事件结果记录列表
     */
    @PreAuthorize(hasPermi ="oms:record:export")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response,FreeviewEventRecord freeviewEventRecord) throws IOException {
        List<FreeviewEventRecord> list = freeviewEventRecordService.selectFreeviewEventRecordList(freeviewEventRecord);
        ExcelUtil<FreeviewEventRecord> util = new ExcelUtil<FreeviewEventRecord>(FreeviewEventRecord.class);
         util.exportExcel(response,list, "record");
    }

    /**
     * 新增全视通事件结果记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存全视通事件结果记录
     */
    @PreAuthorize(hasPermi ="oms:record:add")
    @Log(title = "全视通事件结果记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FreeviewEventRecord freeviewEventRecord)
    {
        return toAjax(freeviewEventRecordService.insertFreeviewEventRecord(freeviewEventRecord));
    }

    /**
     * 修改全视通事件结果记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FreeviewEventRecord freeviewEventRecord = freeviewEventRecordService.selectFreeviewEventRecordById(id);
        mmap.put("FreeviewEventRecord", freeviewEventRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存全视通事件结果记录
     */
    @PreAuthorize(hasPermi ="oms:record:edit")
    @Log(title = "全视通事件结果记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FreeviewEventRecord freeviewEventRecord)
    {
        return toAjax(freeviewEventRecordService.updateFreeviewEventRecord(freeviewEventRecord));
    }

    /**
     * 删除全视通事件结果记录
     */
    @PreAuthorize(hasPermi ="oms:record:remove")
    @Log(title = "全视通事件结果记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(freeviewEventRecordService.deleteFreeviewEventRecordByIds(ids));
    }
}
